package com.future;

import java.util.LinkedList;
import java.util.PriorityQueue;

/**
 * Description:
 * 输入:
 * ["MaxQueue_v1","push_back","push_back","max_value","pop_front","max_value"]
 * [[],[1],[2],[],[],[]]
 * 输出: [null,null,null,2,1,2]
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode.cn/problems/dui-lie-de-zui-da-zhi-lcof
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
 *
 * @author weiruibai.vendor
 * Date: 2022/12/19 09:57
 */
public class Solution_059 {

    public static void main(String[] args) {
        MaxQueue_v1 maxQueue = new MaxQueue_v1();
        maxQueue.push_back(1);
        maxQueue.push_back(2);
        System.out.println(maxQueue.max_value());
        System.out.println(maxQueue.pop_front());
        System.out.println(maxQueue.max_value());
    }
}

class MaxQueue_v1 {

    LinkedList<Integer> linkedList;
    PriorityQueue<Integer> priority;

    public MaxQueue_v1() {
        linkedList = new LinkedList<>();
        priority = new PriorityQueue<>((o1, o2) -> o2 - o1);
    }

    public int max_value() {
        if (priority.isEmpty()) {
            return -1;
        }
        return priority.peek();
    }

    public void push_back(int value) {
        linkedList.add(value);
        priority.add(value);
    }

    public int pop_front() {
        if (linkedList.isEmpty()) {
            return -1;
        }
        Integer remove = linkedList.pollFirst();
        priority.remove(remove);
        return remove;
    }

}